export default {
  namespaced: true,
  state: {
    treeTemplate: {
      children: 'children',
      label: 'name'
    },
    component: {}
  },
  mutations: {
    setComponent(state, payload = {}) {
      state.component = payload
    }
  },
  actions: {
    async init({ dispatch }) {
      await dispatch('getComponent')
    },
    async getComponent({ commit, rootState }) {
      const result = await rootState.service.getComponent()
      // console.log(result,'123')
      if (result.flag && result.data) {
        const uiComponent = {}
        for (const item of result.data) {
          if (item.info && item.info.componentId && item.info.componentFile && item.info.componentId.trim() && item.info.componentFile.trim()) {
            uiComponent[item.info.componentId] = () => import('@page' + '/' + item.info.componentFile)
          }
        }
        await commit('setComponent', uiComponent)
      }
    }
  }
}
